<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">流程编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="sericnum" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" name="created_user" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">申请时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="created_at" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="engin_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">借用类型</label>
                        <div class="layui-input-block">
                            <select name="borrow_type" id="borrow_type"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="cert_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="cert_number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">领证日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="borrow_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">归还日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="return_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="borstatus" name="borstatus" value="">
                                <input type="hidden" id="borrow_type" name="borrow_type" value="1">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <?php include 'dao.php' ?>

        <div class="layui-col-md10" id="table_list">
            <div class="layui-card-body">
                <table id="datalist" lay-filter="datalist"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>
    var currButAuth, currTabData, queryStatus = 0;
    layui.use(['table','form','soulTable'], function () {
        var table = layui.table, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            sea_chanid='';sea_person_nature='';
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        var height_l = $('.laytp-container').height() - 140;
        $('#tree_content').css('cssText','height:'+height_l+'px');
        $('.engindao_bac').css('cssText','height:'+height_l+'px');

        setSouTableExport('原件借用明细');
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_cert_borrow_detail),where: {borrow_type:1}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,contextmenu: get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                if(queryStatus === 0){
                    // var status = res.data.status;
                    // var status_str = '<option value=""></option>';
                    // for (var i in status){
                    //     status_str += '<option value="'+i+'">'+status[i]+'</option>';
                    // }
                    // $('#status').html(status_str);

                    var borrow_type = res.data.borrow_type;
                    var borrow_type_str = '<option value=""></option>';
                    for (var i in borrow_type){
                        borrow_type_str += '<option value="'+i+'">'+borrow_type[i]+'</option>';
                    }
                    $('#borrow_type').html(borrow_type_str);

                    queryStatus = 1;
                }

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{type: 'numbers',title:'序号',fixed:'left'}
                ,{field: 'borstatus_name', title: '状态'}
                ,{field: 'sericnum', title: '流程编号',templet:function (e) {
                    return '<span class="colorlan" onclick="openPage(\'../cert_borrow/show.php?id='+e.borrow_id+'\');">'+e.sericnum+'</span>';
                }}
                ,{field: 'created_user', title: '申请人'}
                ,{field: 'created_at', title: '申请日期'}
                ,{field: 'engin_name', title: '项目名称',event:'engin_name',templet:function (e) {
                        return '<span class="colorlan">'+e.engin_name+'</span>';
                    }}
                ,{field: 'borrow_type_name', title: '借用类型'}
                ,{field: 'cert_type', title: '证书分类'}
                ,{field: 'cert_name', title: '证书名称',event:'cert_name',templet:function (e) {
                        return '<span class="colorlan">'+e.cert_name+'</span>';
                    }}
                ,{field: 'person_name', title: '人员/企业名称'}
                ,{field: 'cert_number', title: '证书编号'}
                ,{field: 'cert_goes', title: '证书去向'}
                ,{field: 'explain', title: '用途说明'}
                ,{field: 'borrow_dt', title: '领取日期'}
                ,{field: 'dt', title: '预计归还日期'}
                ,{field: 'return_dt', title: '归还日期'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1 && currButAuth[key].butname === 'return'){
                            if(item.is_borrow === 2 && item.is_return === 1){
                                chk.append(' <a ' +
                                    'href="javascript:;" ' +
                                    'class="bar_opt layui-hide" ' +
                                    'lay-event="search" ' +
                                    'data-butname="'+currButAuth[key].butname+'" ' +
                                    'data-title="'+currButAuth[key].title+'" ' +
                                    'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                    '>'+currButAuth[key].title+'' +
                                    '</a>');
                            }
                        }
                    }
                });
                show_tab_but(currTabData);


            }
        });

        listTableSearch(form, table);

        table.on('tool(datalist)', function(obj){
            var data = obj.data;
            if(obj.event === 'engin_name'){
                if(data.enginid > 0){
                    openPage('../engin/show.php?id='+data.enginid);
                }
            }
            if(obj.event === 'cert_name'){
                if(data.type == 1){
                    openPage('../cert/show.php?id='+data.certid);
                }else{
                    openPage('../cert_company/show.php?id='+data.certid);
                }
            }
        });
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('../cert_borrow/show.php?id='+trData.borrow_id);
    }
    function auth_but_func_return(buttitle, index){
        var trData = currTabData[index];
        openPage('../cert_borrow/return.php?close=1&id='+trData.id, '80%', '80%');
    }

</script>
</body>
</html>
